var text = [{
  title: '详情', endTime: '报名截止时间',
  reward: '报酬', deadline: '任务截止期限',
  modify: '修改', ph: '输入要修改的自我简介...',
  del: '撤销', comment: '评论',
  cancel: '取消', send: '确定',
  sending: '正在修改', succ: '修改成功',
  short: '介绍太短了', long: '介绍太长了（最长200字）',
}, {
  title: '详情', endTime: '报名截止时间',
  reward: '报酬', deadline: '任务截止期限',
  modify: '修改', ph: '输入要修改的自我简介...',
  del: '撤销', comment: '评论',
  cancel: '取消', send: '确定',
    sending: '正在修改', succ: '修改成功',
  short: '介绍太短了', long: '介绍太长了（最长200字）'
}],
modal = [{
    modify0: '修改后将会重新进行审核哦', modify1: '算了', modify2: '仍要修改',
    del_title: '真的要撤销吗？', del_content: '发布者再也看不到你的报名了！',
    del0: '再想想', del1: '狠心撤销',
    del_succ: '项目已撤销', del_fail: '撤销失败，请稍后再试。',
  }, {
    modify0: '修改后将会重新进行审核哦', modify1: '算了', modify2: '仍要修改',
    del_title: '真的要撤销吗？', del_content: '发布者再也看不到你的报名了！',
    del0: '再想想', del1: '狠心撤销',
    del_succ: '项目已撤销', del_fail: '撤销失败，请稍后再试。',
}];
var animating, sending;
Page({
 

  data: {
    defultAvatar: "/assets/logo/logo.jpg",
    showMask: true,
    sign: false,
    status: 0, // 0审核中，1已提交，2已结束
  },

  onLoad: function (options) {
    sending = animating = 0;
    let item = JSON.parse(decodeURIComponent(options.content));
    if (item.practiceInfo.gmtdead != '0')
      item.deadline = wx.formatTime(new Date(parseInt(item.practiceInfo.gmtdead) * 1e3), '/');
    this.setData({
      status: options.status,
      item: item,
      text: text[wx.lang],
      theme: wx.theme,
      inputText: item.description,
    });
  },

  onShow() {
    wx.onShow(this, text[wx.lang].title, wx.theme);
    let query1 = wx.createSelectorQuery(),
      query2 = wx.createSelectorQuery();
    query1.select('.content').boundingClientRect(content => {
      query2.select('.title').boundingClientRect(title => {
        let scale = parseFloat(wx.system.width / 750);
        // content_height = res.height;
        this.setData({ ch: content.height - 2 * title.height - 40 * scale })
      }).exec();
    }).exec();
  },


  modify() {
    if (animating++) return;
    console.log(animating)
    if (this.data.status == 0) {
      this.showOtherButtons();
    } else if (this.data.status == 1) {
      wx.modal('', modal[wx.lang].modify0, modal[wx.lang].modify1, modal[wx.lang].modify2,
      '#008B00', '#FF3030', () => {
        this.showOtherButtons();
      })
    }
  },
  showOtherButtons() {
    wx.slide_v(this, ['group1'], wx.system.height, 0, .5, () => {
      this.setData({ hideGroup: true });
      wx._slide_v(this, ['group2'], wx.system.height, 0, () => {
        wx.slide_v(this, ['group2'], 0, 1, 0, () => {
          animating = 0;
        })
      })
    })
    wx.hide(this, ['content1'], () => {
      this.setData({ sign: true });
      wx.show(this, ['content2']);
    })
  },


  input(e) {
    console.log(e.detail.value)
    if (e.detail.value.length >= 200) {
      wx.toast(text[wx.lang].long)
    }
    this.setData({ inputText: e.detail.value });
  },

  cancel() {
    wx.toast('正在开发')
  },

  back() {
    if (animating++) return;
    wx.slide_v(this, ['group2'], wx.system.height, 0, .5, () => {
      this.setData({ hideGroup: false });
      wx._slide_v(this, ['group1'], wx.system.height, 0, () => {
        wx.slide_v(this, ['group1'], 0, 1, 0, () => {
          animating = 0;
        });
      });
    });
    wx.hide(this, ['content2'], () => {
      this.setData({ sign: false, });
      wx.show(this, ['content1']);
    });
  },

  // 删除该申请
  del() {
    wx.modal(modal[wx.lang].del_title, modal[wx.lang].del_content,
      modal[wx.lang].del0, modal[wx.lang].del1, null, "#f00", () => {
        let data = {
          idPracticeItem: this.data.item.idpracticeitem,
          idUser: this.data.item.practiceInfo.iduser
        }
        wx.post('PracticeItem.exitJoin', data, e => {
          if (e.success) wx.toast(modal[wx.lang].del_succ, 1);
          else wx.toast(modal[wx.lang].del_fail, 0);
          wx.appData.user.signup = parseInt(wx.appData.user.signup) - 1;
          setTimeout(() => {
            wx.navigateBack({
              delta: 1,
            })
          }, 2000)
        })
      })
  },

  send() {
    console.log('sending=', sending)
    if (sending++) return;
    if (!!this.data.inputText && this.data.inputText[10]) {
      let data = {
        practiceItemInfo: { description: this.data.inputText },
        idPracticeItem: this.data.item.idpracticeitem,
      }
      wx.post('PracticeItem.updatePracticeItem', data, () => {
        wx.toast(text[wx.lang].succ, 1);
        setTimeout(() => {
          sending = 0;
          wx.reLaunch({
            url: '../../me/me',
            // success: () => {
            //   wx.nav('../list/list')
            // },
          })
        }, 1000);
      }, text[wx.lang].sending);
    } else {
      wx.toast(text[wx.lang].short, 0, 1);
      sending = 0;
    }
  },

  onShareAppMessage: function () {
    return wx.onShareAppMessage();
  }
})